package com.teamfractal.fracdustry.common.container.Generators;

import com.teamfractal.fracdustry.common.block.impl.generators.FDKineticGeneratorBlock;
import com.teamfractal.fracdustry.common.container.datasync.SimpleArray;
import com.teamfractal.fracdustry.common.container.init.FDContainers;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;

import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class FDKineticGeneratorContainer extends AbstractContainerMenu {

    private BlockEntity blockEntity;
    private Player playerEntity;
    private IItemHandler playerInventory;
    private SimpleArray currentEnergy;
    private SimpleArray maxEnergy;

    public FDKineticGeneratorContainer(int windowId, Level world, BlockPos pos, Inventory playerInventory, Player player, SimpleArray currentEnergy, SimpleArray maxEnergy) {
        super(FDContainers.containerKineticGenerator.get(), windowId);
        blockEntity = world.getBlockEntity(pos);
        this.playerEntity = player;
        this.playerInventory = new InvWrapper(playerInventory);
        this.currentEnergy = currentEnergy;
        this.maxEnergy = maxEnergy;

        addDataSlots(this.currentEnergy);
        addDataSlots(this.maxEnergy);
    }


    @Override
    public boolean stillValid(@Nonnull Player playerIn) {
        return stillValid(ContainerLevelAccess.create(blockEntity.getLevel(), blockEntity.getBlockPos()), playerEntity, FDKineticGeneratorBlock.BLOCK);
    }

    public ContainerData getCurrentEnergy(){
        return currentEnergy;
    }

    public ContainerData getMaxEnergy(){
        return maxEnergy;
    }

}
